﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ProductManager_products : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void hideButton_Click(object sender, EventArgs e)
    {
        String recordID = Request["__EVENTARGUMENT"].ToString();

        EntityOprHelper helper = new EntityOprHelper();
        String StrSQL = "delete from T_PRODUCT where ID=" + recordID + "";
        bool b = helper.DelEntityBySql(StrSQL);

        if (b)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('删除成功!')", true);
            RecordControl1.UpdataPage();
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('删除失败!')", true);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String recordID = Request["__EVENTARGUMENT"].ToString();
        string[] items=recordID.Split('|');
        if (items.Length == 3)
        {
            string[] values ={ "精品推荐", "热卖商品", "最新商品" };
            //设置状态
            if (items[0] == "0")
            {
                int index =Convert.ToInt16(items[1])-2;
                EntityOprHelper helper = new EntityOprHelper();
                if (index < 3)
                {
                    String StrSQL = "update  T_PRODUCT set SALETYPE='" + values[index] + "' where ID=" + items[2] + "";
                    helper.ExecuteNonQuery(StrSQL);
                }
                else
                {
                    T_PRODUCT product = helper.GetEntityByWhere<T_PRODUCT>(" where ID="+items[2]);
                    if (index == 3)
                    {
                        T_RECOMMEND _recommend = new T_RECOMMEND();
                        _recommend.PID = product.PID;
                        bool b=helper.AddEntity<T_RECOMMEND>(_recommend);
                    }
                    else
                    {
                        if (index == 4)
                        {
                            T_PRODUCT_PROMOTION _recommend = new T_PRODUCT_PROMOTION();
                            _recommend.PID = product.PID;
                            bool b = helper.AddEntity<T_PRODUCT_PROMOTION>(_recommend);
                        }
                    }
                }


            }
            else
            {
                int index = Convert.ToInt16(items[1]) - 2;
                EntityOprHelper helper = new EntityOprHelper();

                if (index < 3)
                {
                    String StrSQL = "update  T_PRODUCT set SALETYPE='' where ID=" + items[2] + "";
                    helper.ExecuteNonQuery(StrSQL);
                }
                else
                {
                    T_PRODUCT product = helper.GetEntityByWhere<T_PRODUCT>(" where ID=" + items[2]);
                    if (index == 3)
                    {
                        String StrSQL = "delete from T_RECOMMEND where PID=" + product.PID + "";
                        helper.ExecuteNonQuery(StrSQL);
                    }
                    else
                    {
                        if (index == 4)
                        {
                            String StrSQL = "delete from T_PRODUCT_PROMOTION where ID=" + product.PID + "";
                            helper.ExecuteNonQuery(StrSQL);
                        }
                    }
                }
            
            }
            RecordControl1.UpdataPage();
        }
    }
}
